#include "test_qr.h"
#include "cm_uart.h"
#include "cm_demo_uart.h"

extern uint16_t *test_camera_buf;

static int cm_test_qr_cb(void *param, const char *data)
{
    cm_demo_printf("param:%s\n",param);
    cm_demo_printf("async data:%s\n",data);
}
void cm_test_qr_operation(unsigned char *cmd[],int len)
{
    if(0 == strcmp("INIT",cmd[2]))
    {

        cm_demo_printf("cm_qr_convert_init ret:%d\n",cm_qr_convert_init(640, 480));
    }
    else if(0 == strcmp("DESTROY",cmd[2]))
    {
        cm_qr_convert_destroy();
        cm_demo_printf("cm_qr_convert_destroy no ret:%d\n");
    }
    else if(0 == strcmp("ASYNC",cmd[2]))
    {
        cm_qr_param_t param = {
            test_camera_buf,    /*!< 图像数据*/
            640,    /*!< 图像宽度*/
            480,   /*!< 图像高度*/
            CM_QR_FMT_UYVY,   /*!< 图像原始格式，需转码为灰阶图像(Y800)*/
            "test_async_qr", /*!< 扫描线程回调的用户传参*/
            cm_test_qr_cb,/*!< 扫描线程回调*/
        };
        cm_qr_scan_async(&param);
        cm_demo_printf("cm_qr_scan_async finish\n");
    }
    else if(0 == strcmp("SYNC",cmd[2]))
    {
        int datalen = 0;
        char data[CM_QR_DATA_LEN_MAX] = {0};
        cm_qr_param_t qr_param = {
            .data   = test_camera_buf,
            .width  = 640,
            .height = 480,
            .format = CM_QR_FMT_UYVY,
            "test_sync_qr", /*!< 扫描线程回调的用户传参*/
            cm_test_qr_cb,/*!< 扫描线程回调*/
        };
        int ret = cm_qr_scan(&qr_param, data, &datalen);
        cm_demo_printf("cm_qr_scan ret:%d, ar qdata:%s\n",ret,data);
    }
    else
    {
        cm_demo_printf("param error!\n");
    }
}